package alibaba.chatApi;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.socket.WebSocketSession;
import reactor.core.publisher.Flux;

import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

@RequestMapping("alibaba")
@RestController
public class Chat {

    public static void main(String[] args) {
        ConcurrentHashMap<Integer, WebSocketSession> sessionMap = new ConcurrentHashMap<>();
    }

    ChatClient chatClient;

    public Chat(ChatClient.Builder builder) {
        this.chatClient = builder.build();
    }

    @GetMapping("/chat")
    public String chat(@RequestParam("msg") String message) {
        return chatClient.prompt(message).call().content();
    }

    @GetMapping(value = "stream", produces = "text/html;charset=utf-8")
    public Flux<String> stream(@RequestParam("msg") String message) {
        return chatClient.prompt(message).stream().content();
    }
}
